# project
cmake_minimum_required(VERSION 2.8.8)
set(TARGET spice_vcd_test)
project(${TARGET})

include_directories(
    ../
    )

aux_source_directory( ../vcd-common-api TEST_SRC_DIR)
aux_source_directory( ../vcd-common-api/trace-signals TEST_SRC_DIR)
aux_source_directory( ../vcd-common-api/vcd-conf TEST_SRC_DIR)
aux_source_directory( ../vcd-common-api/vcd-ping-impl TEST_SRC_DIR)
aux_source_directory( ../vcd-common-api/vcd-topbar TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window/setting-close TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window/setting-diagnosis TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window/setting-main TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window/setting-network TEST_SRC_DIR)
aux_source_directory( ../vcd-linux-ui/vcd-setting-window/setting-other TEST_SRC_DIR)
aux_source_directory( ../vcd-common-api/easylog TEST_SRC_DIR)
aux_source_directory( ../vcd-rdp TEST_SRC_DIR)
set(TEST_SRC
    ../spicy.c
    ../spicy-connect.c
    ../spice-cmdline.c
)

# compile
#set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_EXE_LINKER_FLAGS '-Wl,-rpath=/usr/local/lib')
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ggdb3 -O0 -Wmissing-declarations -Werror -Wall")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Wwrite-strings -Wcast-align")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith -m64 -Wredundant-decls")

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -O0 -Wmissing-declarations -Werror -Wall")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wuninitialized -Wwrite-strings -Wcast-align")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -m64 -Wredundant-decls")

#http://www.cppblog.com/jinq0123/archive/2012/07/11/182790.html
#OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF)
#IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
#  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
#  SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
#  SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
##ENDIF()
#以上代码来自MySQL的CMakeLists.txt.
#如下执行cmake:
#cmake SRC_DIR -DCMAKE_BUILD_TYPE=Debug -DENABLE_GCOV=1
#编译后就可以看到图文件 *.gcno。
#运行后，可以看到数据文件*.gcda生成。
#执行 gcov main.cpp.gcno 就生成 main.cpp.gcov 测试结果


SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs --coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs --coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ftest-coverage -fprofile-arcs -lgcov --coverage")

# check gtest
pkg_check_modules(GTEST REQUIRED gtest)
include_directories( ${GTEST_INCLUDE_DIRS} )
set( COMMON_LIBS ${COMMON_LIBS} ${GTEST_LIBRARIES} )

# target
add_executable(${TARGET} test_gtest_example.cpp ${TEST_SRC} ${TEST_SRC_DIR})

IF(WIN32)
    target_link_libraries(${TARGET} -lgtest ${COMMON_LIBS} ${VCD_LINK_WIN32_LIB})
ELSEIF(UNIX)
    target_link_libraries(${TARGET} -lgtest ${COMMON_LIBS} ${VCD_LINK_LINUX_LIB})
ELSE()
    target_link_libraries(${TARGET} -lgtest ${COMMON_LIBS})
ENDIF()
